import { createRouter, createWebHashHistory } from 'vue-router'

import Layout from '@/layout/index.vue'

export const constantRoutes = [

  {
    path: '/',
    redirect: '/main',
    hidden: true
  },

  {
    path: '/main',
    component: Layout,
    redirect: '/main/chat',
    children: [
      {
        path: 'chat',
        name: 'chat',
        component: () => import('@/views/chat/index.vue'),
        meta: { title: '聊天' },
        hidden: true
      },
      {
        path: 'manage',
        name: 'manage',
        component: () => import('@/views/manage/index.vue'),
        meta: { title: '管理' },
        hidden: true
      },
    ]
  },
  


  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },

]

export const asyncRoutes = [

  {
    path: '/:pathMatch(.*)*',           // vue-router4中不能直接匹配'*'；或者改为'/:catchAll(.*)'
    redirect: '/404',
    hidden: true
  }
]


const newRouter = () => createRouter({
  history: createWebHashHistory(),
  scrollBehavior() {
    return { top: 0, behavior: 'smooth' }
  },
  routes: constantRoutes
})

const router = newRouter()

export const resetRouter = () => {
  const cRouter = newRouter()
  router.matcher = cRouter.matcher // reset router
}

export default router
